﻿  function newLogin() {
      var params=document.getElementById("newLoginFormRender");
      var f=document.getElementById("newLoginForm");
      if (params.username.value=="") {
        alert("请输入您的用户名");
        return;
      }else{
        f.username.value=params.username.value+'_762089b6-11dd-1000-93d2-4dc23a3e1c3f';
      }

      if (params.password.value=="" || params.password.value.length<6) {
        alert("请输入您的密码（不少于6位）");
        return;
      }else{
        f.password.value='XMD5:'+MD5(params.password.value);
      }

      var callback =
      {
          success: function(o) {
			//删除错误的二级域名下的xpeSessionId
			YAHOO.util.Cookie.remove("xpeSessionId",{path:"/"});
			//YAHOO.util.Cookie.remove("xpeSessionId",{domain:s,path:"/"});
            var res = eval("(" + o.responseText + ")");
            if (res.status=='success') {
				YAHOO.util.Connect.asyncRequest('GET','/xpe/portal/service/e5798096-12f9-1000-938d-306afaed6829', null, null);
                window.location=window.location;
            } else if(res.status=='error'&&res.id){
                document.getElementById("login_hasUserClickLoginButton_newLogin").innerHTML="";
                alert(res.body);
            } else {
                document.getElementById("login_hasUserClickLoginButton_newLogin").innerHTML="";
                alert("登录失败！请确认您输入了正确的用户名/电子邮件和密码！");
            }
          },
          failure: function(o) {
			YAHOO.util.Cookie.remove("xpeSessionId",{path:"/"});
            alert("服务器繁忙或网络错误，请重试。");
            document.getElementById("login_hasUserClickLoginButton_newLogin").innerHTML="";
          },
          timeout: 10000
      }

      if(document.getElementById("login_hasUserClickLoginButton_newLogin").innerHTML!="yes"){
          document.getElementById("login_hasUserClickLoginButton_newLogin").innerHTML="yes";
          YAHOO.util.Connect.resetFormState();
          YAHOO.util.Connect.setForm(f);
          YAHOO.util.Connect.asyncRequest('POST','/xpe/jingpinke/service/security/json/login', callback, null);
      }
  }

  

  function newLogin2() {
	  var el=document.getElementById("newLoginDiv");
	  var user=YAHOO.util.Cookie.get("user");

	  if(user&&user.indexOf("|")!=-1){
			//用户已经登录,设置页头用户登录后信息
			var infos=user.split("|");
			if(infos.length>=3){
				var name=infos[1];
				var role=infos[2];
				if(role.indexOf("union")!=-1){
					role="联盟会员";
				}else{
					role="注册会员";
				}
				var s='<div class="user_login">欢迎，'+name+'（'+role+'）<a href="/xpe/jingpinke/service/signOff?target=http://www.jingpinke.com">退出</a><a href="http://www.jingpinke.com/my" class="b">我的个人中心</a><a href="http://www.jingpinke.com/my/point/introduction">会员积分说明</a><a href="http://www.jingpinke.com/help?uuid=72766a4a-129c-1000-b066-92883a664df0" class="b">帮助</a><a href="javascript:XPE.bus.occurred(\'addfavorite\',\'\')"  title="即送10个积分" class="favoriteSite">收藏本站</a></div>';
				var s2='欢迎，'+name+'  <a href="http://www.jingpinke.com/my">进入个人中心</a><a href="/xpe/jingpinke/service/signOff?target=http://www.jingpinke.com">退出</a><a target="_blank" href="http://www.jingpinke.com/help?uuid=72766a4a-129c-1000-b066-92883a664df0">帮助</a><a title="即送10个积分" class="favoriteSite" href="javascript:XPE.bus.occurred(\'addfavorite\',\'\')">收藏本站</a>';
				if(el){
					if(YAHOO.util.Dom.hasClass(el,"newLoginSimple")){
						el.innerHTML=s2;
					}else{
						el.innerHTML=s;
					}
				}
			}
	  }
  }


 YAHOO.util.Event.onContentReady("newLoginDiv", newLogin2);

